package com.ipad.net.mvp;

import android.os.Handler;

import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class BasePresenterImpl<V extends BaseView> implements BasePresenter<V>{
    protected V mView;
    private boolean display = true;

    @Override
    public void attachView(V view) {
        mView=view;
    }

    @Override
    public void detachView() {
        mView=null;
    }

    Handler handler = new Handler();

    public void addSubscribe(Flowable flowable, FlowableSubscriber flowableSubscriber) {
        flowable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(flowableSubscriber);
    }

    public void post(Runnable runnable) {
        handler.post(runnable);
    }

    public void showDialog(String msg){
        if (display){
            mView.loading(msg);
        }
    }
    public void dismissDialog(){
            mView.stopLoading();
    }

}
